import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../public'

type ModelProps = {
  id: number
  name: string
}

class goods extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

goods.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false
    },
    name: {
      type: DataTypes.STRING(20),
      primaryKey: true,
      allowNull: false,
      comment: '名字'
    }
  },
  {
    sequelize,
    tableName: 'goods',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      },
      {
        unique: true,
        fields: ['name']
      }
    ]
  }
)

export { goods }
